<?php

/**
 * home actions.
 *
 * @package    spidersec
 * @subpackage home
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class homeActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    //$this->forward('default', 'module');
    $this->add_form = new SiteForm();
    if ($values = $request->getParameter($this->add_form->getName()))
    {
    	$this->add_form->bind($values);
    	if ($this->add_form->isValid())
    	{
    		$this->add_form->getObject()->setStatus(Site::WAITING);
    		$this->add_form->save();
    		$this->indexSite($this->add_form->getObject());
    	}
    }

    $this->sites = Doctrine_Core::getTable("Site")->findAll();
  }

  public function executeGetpages(sfWebRequest $request)
  {
  	sfConfig::set('sf_web_debug',false);
  	$site_id = $request->getParameter("site_id");
  	if ($site = Doctrine_Core::getTable("Site")->find($site_id))
  	{
  		$pages = Doctrine_Core::getTable("Page")->createQuery("p")->addWhere("p.site_id = ?", $site->getId())->orderBy("risk asc")->execute()->toArray();
  	}
  	return $this->renderText(json_encode($pages));
  }

  private function indexSite($site)
  {
  	pclose(popen("start php ".sfConfig::get("sf_web_dir").DIRECTORY_SEPARATOR."spider.php ".$site->getUrl(),"r"));
  }
}
